package ee.karileet.productcatalogue.service.impl;

import ee.karileet.productcatalogue.dao.IUserHome;
import ee.karileet.productcatalogue.dao.impl.UserHome;
import ee.karileet.productcatalogue.model.User;
import ee.karileet.productcatalogue.service.IUser;

public class UserSrv implements IUser {

	private IUserHome home;
	
	public UserSrv() {
		home = new UserHome();
	}
	
	public boolean addUser(User user) {
		home.save(user);
		return false;
	}

	public User getUser(int userId) throws Exception {
		if (!(userId > 0)) throw new Exception("ID must be greater than 0");
		return home.findById(userId);
	}

	public java.util.Set<User> listUsers() {
		return new java.util.HashSet<User>(home.findAll());
	}

	public void removeUser(int userId) throws Exception {
		if (!(userId > 0)) throw new Exception("ID must be greater than 0");
		User u = home.findById(userId);
		home.delete(u);
	}

	public boolean updateUser(User user) {
		// TODO Auto-generated method stub
		return false;
	}

}
